package com.my.cloud.resp;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/3/7 14:55
 */
@Data
@Accessors(chain = true)
public class ResultData<T> {
    
    // 结果状态
    private String code;
    private String msg;
    private T data;
    // 什么时候调用的接口
    private long timestamp;
    
    public ResultData(){
        this.timestamp = System.currentTimeMillis();
    }
    
    public static <T> ResultData<T> success(T data){
        ResultData resultData = new ResultData();
        resultData.setCode(ReturnCodeEnum.RC200.getCode());
        resultData.setMsg(ReturnCodeEnum.RC200.getMsg());
        resultData.setData(data);
        return resultData;
    }

    public static <T> ResultData<T> failure(String code, String msg){
        ResultData resultData = new ResultData();
        resultData.setCode(code);
        resultData.setMsg(msg);
        resultData.setData(null);
        return resultData;
    }
}
